import http from "./http";

function getPostsList() {
    return http.post('/api/bbs/bbsPosts/open/list')
}
function getCategoryList() {
    return http.post('/api/bbs/bbsCategory/open/list')
}
//点击主题获取响应帖子列表
function getThemePostsList(categoryId) {
    let formdata = new FormData()
    formdata.append("categoryId", categoryId)
    return http.post("/api/bbs/bbsPosts/open/list", formdata)
}

//获取帖子详情
function getPostsDetails(postsId) {
    return http.get(`/api/bbs/bbsPosts/open/detail/${postsId}`)
}
//获取评论文本的
function getCommentContent(postsId) {
    let formdata = new FormData()
    formdata.append('postsId', postsId)
    // formdata.append('rememberMe',true)
    return http.post('/api/bbs/bbsComment/open/list', formdata)
}

//发送评论
function sendComment(postsId, commentContent) {
    let formdata = new FormData()
    formdata.append('postsId', postsId)
    formdata.append('commentContent', commentContent)
    // formdata.append('rememberMe',true)
    return http.post('/api/bbs/bbsComment/site/add', formdata)
}

//发送评论的回复
function sendCommentReply(postsId, parentId, commentContent) {
    let formdata = new FormData()
    formdata.append('postsId', postsId)
    formdata.append('parentId', parentId)
    formdata.append('commentContent', commentContent)
    // formdata.append('rememberMe',true)
    return http.post('/api/bbs/bbsComment/site/reply/add', formdata)
}

//获取评论回复列表
function getCommentReplyList(parentId) {
    let formdata = new FormData()
    formdata.append('parentId', parentId)
    // formdata.append('rememberMe',true)
    return http.post('/api/bbs/bbsComment/open/reply/list', formdata)
}

//删除帖子
function deletePost(ids) {
    let formdata = new FormData()
    formdata.append('ids', ids)
    return http.post('/api/bbs/bbsPosts/site/remove', formdata)
}

//删除评论
function deleteComment(ids) {
    let formdata = new FormData()
    formdata.append('ids', ids)
    return http.post('/api/bbs/bbsComment/site/remove', formdata)
}

//搜索
function getSearch(title) {
    let formdata = new FormData()
    formdata.append("title", title)
    return http.post("/api/bbs/bbsPosts/open/list", formdata)
}

//登录
function toLogin(username, password) {
    let formdata = new FormData()
    formdata.append("username", `${username}`)
    formdata.append("password", `${password}`)
    formdata.append("rememberMe", true)
    return http.post('/api/login', formdata)
}

//获取我参与的
function getMyPosts() {
    return http.post('/api/bbs/bbsPosts/join/list')
}

//发布帖子
function Publish(categoryId, title, intro, coverImgUrl) {
    let formdata = new FormData()
    formdata.append('categoryId', categoryId)
    formdata.append('title', title)
    formdata.append('intro', intro)
    formdata.append('coverImgUrl', coverImgUrl)
    return http.post('/api/bbs/bbsPosts/site/add', formdata)
}
export {
    getPostsList,
    getCategoryList,
    getThemePostsList,
    getPostsDetails,
    getCommentContent,
    sendComment,
    sendCommentReply,
    getCommentReplyList,
    deletePost,
    getSearch,
    toLogin,
    getMyPosts,
    Publish,
    deleteComment
}